package cn.edu.scau.cmi.zeyang.controller;

import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.zeyang.abstractfactory.AbstractFactory;
import cn.edu.scau.cmi.zeyang.domain.insurance.Insurance;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;

public class AbstractFactoryController {

	@FXML
	private Button button;

	@FXML
	private ChoiceBox<String> insuranceChoiceBox;

	@FXML
	private ChoiceBox<String> companyChoiceBox;

	@FXML
	private TextArea textArea;

	public void initialize() {
		insuranceChoiceBox.setValue("司机受伤");
		insuranceChoiceBox.setItems(FXCollections.observableArrayList("司机受伤","汽车损坏","人员伤亡","多种事故"));
		companyChoiceBox.setValue("PICC");
		companyChoiceBox.setItems(FXCollections.observableArrayList("PICC", "PingAn"));
		textArea.setDisable(true);
		textArea.setWrapText(true);
		button.setOnAction(e -> {
			AbstractFactory factory = AbstractFactory.getFactory(companyChoiceBox.getValue());
			if (factory != null){
				Insurance insurance = factory.createInsurance(insuranceChoiceBox.getValue());
				if(insurance!=null){
					textArea.setText("你已选择"+companyChoiceBox.getValue()+"的"+insuranceChoiceBox.getValue()+":"+insurance.getDetail());
				}else{
					textArea.setText("保险类型错误");
				}
			}
			else{
				textArea.setText("选择保险公司错误");
			}
		});
	}

}
